
<%@ page language="java" %>

<%@ page import="java.util.ArrayList,
                com.scalar.chiptrack.utils.StringUtils,
                com.scalar.chiptrack.commons.Address,
                com.scalar.chiptrack.commons.Constants,
                com.scalar.chiptrack.sales.SalesOrder,
                com.scalar.chiptrack.sales.LineItem,
                com.scalar.chiptrack.utils.ConfigManager,
                com.scalar.chiptrack.users.User,
                com.scalar.chiptrack.users.Functionality,
                com.scalar.chiptrack.commons.SessionKeys,
                com.scalar.chiptrack.operations.packingslip.forms.CommercialInvoiceForm,
                com.scalar.chiptrack.commons.Constants"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/commercialInvoice.do"/>

<%
    String chipTracContext = "/" + ConfigManager.getChipTracContext();
    User user1 = ( User ) session.getAttribute( SessionKeys.USER_KEY );
%>

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js">
</script>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</script>
<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">

<SCRIPT language="JavaScript">


function saveInvoice()
{
    document.commercialInvoiceForm.submit();
}

function cancelAndGoBack()
{
    window.close();
}

function showInvoice()
{
    if( ( document.commercialInvoiceForm.salesOrderId.value != -1 ) && ( document.commercialInvoiceForm.customerShippingId.value != -1 ) )
    {
        var invoiceURL = '<%=chipTracContext%>/commercialInvoice.do?action=showInvoice&salesOrderId=' + document.commercialInvoiceForm.salesOrderId.value + '&customerShippingId=' + document.commercialInvoiceForm.customerShippingId.value;
        newWindow = window.open (invoiceURL,'commInvoicePrinterFriendly','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,resizable=yes');
        newWindow.focus();
    }
}

// Balaram on July 29, 2003
function showErrorReportPage()
{
    newWindow = window.open ('<%=chipTracContext%>/reportProblem.do','reportProblem','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=750,height=400,resizable=no');
    newWindow.focus();
}


</SCRIPT>


<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>


<!-- body starts -->

<center><span class="NArialW">Commercial Invoice</span></center>
<center>&nbsp;&nbsp;<a href='javascript:showInvoice()'  onMouseOver="window.status='Click for Printer Friendly Version ';return true" onMouseOut="window.status='';return true" title='Click here for Printer Friendly version'><font class='NArialS'><b>[Printer-Friendly]</b></font></a></center>

<html:form name="commercialInvoiceForm" type="com.scalar.chiptrack.operations.packingslip.forms.CommercialInvoiceForm" action="/commercialInvoice.do?action=save&fromEmailPS=yes">
<html:hidden name="commercialInvoiceForm" property="customerShippingId"/>
<html:hidden name='commercialInvoiceForm' property='salesOrderId'/>
<html:hidden name='commercialInvoiceForm' property='packingSlipNumber'/>
<html:hidden name='commercialInvoiceForm' property='totalWeight'/>
<html:hidden name='commercialInvoiceForm' property='totalPackages'/>
<html:hidden name='commercialInvoiceForm' property='status'/>
<html:hidden name='commercialInvoiceForm' property='shippingFromLocationId'/>

    <%
        // added by hareesh on 5th September 2003
        CommercialInvoiceForm commericalInvoiceForm = (CommercialInvoiceForm) request.getAttribute ("commercialInvoiceForm");

        SalesOrder salesOrder = (SalesOrder) request.getAttribute ("salesOrder");

        if( salesOrder != null )
        {
            Address billingAddress = salesOrder.getBillingAddressAsObject();
            //changed by hareesh on 5th September 2003
            //Address shippingAddress = salesOrder.getShippingAddressAsObject();
            Address shippingAddress = salesOrder.getShippingAddressAsObject();
    %>

    <table width="95%" cellspacing='0' cellpadding='0' border=0 align=center>

        <tr><td colspan='5'><chiptrack:info styleClass='NArialL'/></td></tr>
        <tr><td colspan='5'><chiptrack:errors styleClass='NArialL'/></td></tr>
         <% if ( !user1.isActionAllowed ( Functionality.COMMERCIAL_INVOICE,
         User.USER_ACTION_MODIFY ) ) { %>
            <tr><td colspan='5'><font class='NArialS'><font color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b></font></font></td></tr>
        <% } %>
        <!--changed by hareesh on 20th August 2003-->
        <!-- START : to include Ship to address -->
        <tr height=30>
            <td width="34%" class="NArialL" bgcolor="#DEE1E2" >&nbsp;Shipper :</td>
            <td width='1%'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td>
            <td widht="30%" class="NArialL" bgcolor="#DEE1E2" >&nbsp;Bill To :</td>
            <td width='1%'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td>
            <td width="34%"  bgcolor="#DEE1E2"><font class="NArialL">&nbsp;Ship To:</font></td>
        </tr>
        <tr>
            <td bgcolor='#FFFFEE' class="NArialL" valign="top">
                <table width="100%" class="NArialL" valign="top">

                    <%--Added by Krishna Prasad on 27 May 2004--%>
                    <tr>
                        <td  valign="top">
                            <bean:write  name="commercialInvoiceForm" property="clientName"/>
                            <br>
                            <bean:write name="commercialInvoiceForm" property="shipperVendorAddressAsHTML" filter="false"/>
                        </td>
                    </tr>
                </table>
            </td>

            <td width='1%'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td>
            <td width="30%" bgcolor='#FFFFEE' class="NArialL" valign="top">
                <table width='100%' class='NArialL'><tr><td valign="top">
                   <bean:write name="commercialInvoiceForm" property="billingAddressAsHTML" filter="false"/> <%--// Added by Krishna Prasad on 26 May 2004--%>
                </td></tr></table>
            </td>
            <td width="1%" bgcolor='#FFFFFF' class="NArialL" valign="top"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td>
            <td width='34%' bgcolor='#FFFFEE' class="NArialL"  valign="top">
				<table width='100%' class='NArialL'><tr><td valign="top">
                    <bean:write name="commercialInvoiceForm" property="shippingAddressAsHTML" filter="false"/>
            </td></tr></table>

            </td>
       </tr>
       <tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tR>

       <tr>
            <td class="NArialL" colspan='5'>
                <table width="100%" class="NArialL">
                    <tr height=30>
                        <td bgcolor='#DEE1E2' align=center>Customer PO#</td>
                        <td bgcolor='#DEE1E2' align=center>Sales Order#</td>
                        <td bgcolor='#DEE1E2' align=center>Packing Slip#</td>
                        <td bgcolor='#DEE1E2' align=center><bean:message key="label.commercialInvoice.commercialInvoiceNo"/></td>
                        <td bgcolor='#DEE1E2' align=center>INCOTERMS</td>
						<td bgcolor='#DEE1E2' align=center>Way Bill</td>
                        <td bgcolor='#DEE1E2' align=center>Country of <br>Origin(Fab)</td>
                        <td bgcolor='#DEE1E2' align=center>Country of <br>Origin(Assy)</td>
                    </tr>
                    <tr height=30>
                        <td bgcolor='#FFFFEE' nowrap align=center><%=((salesOrder.getCustomerPO() == null) ? "" : salesOrder.getCustomerPO())%></td>
                        <td bgcolor='#FFFFEE' nowrap align=center><%=salesOrder.getSalesOrderNo()%></td>
                        <td bgcolor='#FFFFEE' nowrap align=center><bean:write name='commercialInvoiceForm' property='packingSlipNumber'/></td>
                        <td bgcolor="#FFFFEE" nowrap align=center><bean:write name="commercialInvoiceForm" property="commercialInvoiceNo"/></td>
                        <td bgcolor='#FFFFEE' nowrap align=center>
                        <bean:write name='commercialInvoiceForm' property='fob' />
                        <html:hidden name='commercialInvoiceForm' property='fob' />
                        </td>						<td bgcolor='#FFFFEE' align=center>
							<table class="NArialL">
							<logic:iterate name="commercialInvoiceForm" property="frieghtTrackingNumber" id="track">
							<tr><td>
								<bean:write name="track"/>
							</tr></td>
							</logic:iterate>
							</table>	
						</td>

                        <td bgcolor='#FFFFEE' nowrap align=center><html:text name='commercialInvoiceForm' property="countryOfFabOrigin" styleClass='txfield' maxlength='50'/></td>
                        <td bgcolor='#FFFFEE' nowrap align=center><html:text name='commercialInvoiceForm' property='countryOfAssyOrigin' styleClass='txfield' maxlength='50'/></td>
                    </tr>
                </table>
            </td>
       </tr>
	   <tr><td colspan="5" class='NArialL' align='left'>Comments</td></tr>
	   <tr><td colspan="5" class='NArialL' align='left'>
	   <html:textarea rows="3" name="commercialInvoiceForm" property="comments" cols="100" styleClass="txfield"  onkeydown="javascript:setTextAreaMaxLength(document.commercialInvoiceForm.comments,300)" onkeyup="javascript:setTextAreaMaxLength(document.commercialInvoiceForm.comments,300)"/>
	   </td></tr>

       <tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tR>

       <tr><td colspan='5'><hr class ="NArialL"></td></tr>

       <tr><td colspan='5'>
       <table width="100%" border=0 cellpadding='0' cellspacing='2' bordercolor='#000000'>
            <tr height=30>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>PO Line Item</td>
                <% if (ConfigManager.getBooleanProperty(ConfigManager.SHOW_MFG_PARTNO_PACKINGSLIP ) ) { %>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>
				<bean:message key = "label.mfgPartNumber" /></td>
                <% } %>
                <% if (ConfigManager.getBooleanProperty(ConfigManager.SHOW_MRKT_PARTNO_PACKINGSLIP ) ) { %>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>
				<bean:message key = "label.mktgPartNumber" /></td>
                <% } %>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>
				<bean:message key = "label.customerPartNumber" /></td>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>Product <br>Description</td>
				<td class="NArialL" bgcolor="#DEE1E2" align=center>Units</td>
                <td class="NArialL" bgcolor="#DEE1E2" align=center><bean:message key="label.commercialInvoice.ScheduleNumber"/></td>
                <td class="NArialL" bgcolor="#DEE1E2" align=center><bean:message key="label.commercialInvoice.ScheduleNumberDiscription"/></td>
				<td class="NArialL" bgcolor="#DEE1E2" align=center><bean:message key="label.commercialInvoice.ECCN"/></td>
				<td class="NArialL" bgcolor="#DEE1E2" align=center><bean:message key="label.commercialInvoice.LicenseSymbol"/></td>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>Shipped Qty</td>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>Unit<br>Price</td>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>Line<br>Total</td>
            </tr>

            <%
                ArrayList lineItemList = ( ArrayList ) request.getAttribute( "lineItems" );

                float totalSalesTaxValue = 0f; // added by hareesh on 31st July 2003
                float salesTaxValue = salesOrder.getSalesTaxValue(); // added by hareesh on 31st July 2003

                if( ( lineItemList != null ) && ( lineItemList.size() != 0 ) )
                {
                    int lineItemListSize = lineItemList.size();
                    LineItem lineItem = null;
            %>
                <input type='hidden' name='lineItemListSize' value='<%=lineItemListSize%>'/>
            <%
                    for( int i = 0; i <= ( lineItemListSize-1 ); i++ ) // added by hareesh on 10th July 2003
                    {
                        lineItem = ( LineItem ) lineItemList.get( i );
                        if(lineItem.getIsTaxable()){
                            totalSalesTaxValue += lineItem.getAmount();
                        }
						String customerPartNumber = lineItem.getCustomerPartNumber();
						String description = lineItem.getDescription();

            %>
                    <tr height=30>
                        <td bgcolor='#FFFFEE' class="NArialL" align=center nowrap>&nbsp;<%=(lineItem.getPoLineItemNo() < 1?"":lineItem.getPoLineItemNo()+"") %></td>
                        <% if (ConfigManager.getBooleanProperty(ConfigManager.SHOW_MFG_PARTNO_PACKINGSLIP ) ) { %>
                        <td bgcolor='#FFFFEE' class="NArialL" align=center nowrap><%=lineItem.getManufacturingPartNo()%></td>
                        <% } if (ConfigManager.getBooleanProperty(ConfigManager.SHOW_MRKT_PARTNO_PACKINGSLIP ) ) { %>
                        <td bgcolor='#FFFFEE' class="NArialL" align=center nowrap><%=lineItem.getMarketingPartNo()%></td>
                        <% } %>
                        <td bgcolor='#FFFFEE' class="NArialL" align=center nowrap><%=(lineItem.getCustomerPartNumber() != null) ? 
							lineItem.getCustomerPartNumber(): "&nbsp;" %></td>
                        <td bgcolor='#FFFFEE' class="NArialL" align=center ><%=( ( lineItem.getDescription() == null ) || ( lineItem.getDescription().trim().length() == 0 ) ) ? "&nbsp;" : lineItem.getDescription()%></td>
						<td bgcolor="#FFFFEE" class="NArialL" align=right nowrap><%=( ( lineItem.getUom() == null ) || ( lineItem.getUom().trim().length() == 0 ) ) ? "&nbsp;" : lineItem.getUom()%></td>
                        <td bgcolor='#FFFFEE' class="NArialL" align=center nowrap>
                            <input type='hidden' name='<%="lineItemId_" + i%>' value='<%=lineItem.getLineItemId()%>'/>
                            <input type='text' name='<%="scheduleNumber_" + i%>' value='<%=lineItem.getScheduleNumber() %>' maxlength='50' class='txfield' disabled="true"/>
                        </td>

                        <td bgcolor='#FFFFEE' class="NArialL" align=center nowrap>
                            <input type='hidden' name='<%="lineItemId_" + i%>' value='<%=lineItem.getLineItemId()%>'/>
                            <input type='text' name='<%="scheduleDescription_" + i%>' value='<%=lineItem.getScheduleDescription()%>' maxlength='50' class='txfield' disabled="true"/>
                        </td>

                        <td bgcolor='#FFFFEE' class="NArialL" align=center nowrap>
                            <input type='text' name='<%="eccn_" + i%>' value='<%=lineItem.getEccn()%>' maxlength='50' class='txfield' disabled="true"/>
                        </td>
                        <td bgcolor='#FFFFEE' class="NArialL" align=center nowrap>
                            <input type='text' name='<%="licenseException_" + i%>' value='<%=( ( lineItem.getLicenseException() == null ) || ( lineItem.getLicenseException().trim().length() == 0 ) ) ? "" : lineItem.getLicenseException()%>' maxlength='50' class='txfield'  disabled="true"/>
                        </td>

						<td bgcolor='#FFFFEE' class="NArialL" align=right nowrap><%=lineItem.getQtyAsString()%></td>
                        <td bgcolor='#FFFFEE' class="NArialL" align=right nowrap><%=lineItem.getDisplayUnitPrice()%></td>
                        <td bgcolor='#FFFFEE' class="NArialL" align=right nowrap><%=lineItem.getAmountAsString()%></td>
                    </tr>
            <%
                    }       // while (lineItems.hasNext()) ...
                }           // if ((lineItemList != null) ...
            %>

        </table>
       </td></tr>

        <tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tR>

        <tr><td colspan=5 bgcolor='#DEE1E2' align="right"><font class='NArialL'>
        Grand Total:<%=StringUtils.formatAmountWithNoOfDecimals( ( salesOrder.getSubTotalAsDouble() ))%>
        </font></td></tR>

        <tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=40></td></tR>

        <tr><td colspan=5>
        <table width='100%' border='0'>
            <tr>
                <td width='20%' class='NArialL' align='right'>TOTAL PKGS:</td>
                <td width='5%'  class='NArialL' align='center'><bean:write name='commercialInvoiceForm' property='totalPackagesStr'/></td>
                <td width='5%' class='NArialL' align='right'>&nbsp;</td>

                <td width='45%' class='NArialL' align='right'>&nbsp;</td>
                <td width='20%' class='NArialL' align='right'>&nbsp;<!-- License Symbol: --></td>
                <td width='5%'  class='NArialL' align='left'><!-- <h t m l : t e x t   n am e = ' c om m e r ci a l I n v o ic e F o rm ' maxlength='50' property='licenseSymbol' styleClass='t x f ie l d '/ > -->&nbsp;</td>
            </tr>
            <tr>
                <td width='20%' class='NArialL' align='right'>
					<% if( ConfigManager.getShowPackageDimensionInPackingSlip() ) { %>
                    NET WEIGHT:
                    <% } else { %>
                    WEIGHT:
                    <% } %>
				</td>
                <td width='5%'  class='NArialL' align='center'><bean:write name='commercialInvoiceForm' property='totalWeight'/></td>
                <td width='5%' class='NArialL' align='left'>
                    &nbsp;&nbsp;
                    <logic:notEqual value="" name="commercialInvoiceForm" property="totalWeight">
                    <bean:write name='commercialInvoiceForm' property='weightType'/>
                    </logic:notEqual>
                    &nbsp;
                </td>
                <td width='45%' class='NArialL' align='left'>&nbsp;</td>
                <td width='20%' class='NArialL' align='right'>&nbsp;<!-- ECCN: --></td>
                <td width='5%'  class='NArialL' align='left'>&nbsp;<!-- < h t ml : t ex t   n am e = ' co m mercialInvoiceForm' maxlength='50' property='eccn' styleClass='txfield' / > --></td>
            </tr>
        </table>
        </td></tr>

        <tr><td colspan=5 align='center'>
         <%
            String status = commericalInvoiceForm.getStatus().trim();
            if ( ( Constants.CUSTOMER_SHIPPING_STATUS_CANCELLED != status ) && ( Constants.CUSTOMER_SHIPPING_STATUS_SHIPPED != status ) )
            {
         %>

                <chiptrack:restrictedLink functionality='<%=Functionality.COMMERCIAL_INVOICE%>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:saveInvoice();' onmouseover="window.status='Click to save this Commercial Invoice';return true" onmouseout="window.status='';return true">
                <img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" title='Click here to save this Commercial Invoice'></chiptrack:restrictedLink>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         <%
            }
         %>
	    <a href="javascript:cancelAndGoBack();" onMouseOver="window.status='Click to Cancel and go back ';return true" onMouseOut="window.status='';return true" title="Click here to Cancel and go back ">
        <img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif"></a>
        </td></tr>

        <tr><td colspan=5 align='center'><br></td></tr>

        <tr><td colspan=5 align='center'>
        <a href="javascript:window.close();" title='Click here to close this window' onMouseOver="window.status='Click here to close this window';return true"><font class='NArialL'><b>[Close this window]</b></font></a>
        </td></tr>

    </table>



    <%
        }       // if (salesOrder != null)...
    %>



</html:form>

<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

</body>
</html>
